const cloud = require('wx-server-sdk')

cloud.init({
  env: 'web-zgy-jdrxj',
  traceUser: true,
})

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.subscribeMessage.send({
      "touser": cloud.getWXContext().OPENID,
      "page": 'pages/index/index',
      "data": {
        "thing1": {
          "value": event.thing1
        },
        "date2": {
          "value": event.date2
        },
        "thing3": {
          "value": event.thing3
        },
        "thing4": {
          "value": event.thing4
        }
      },
      "templateId": 'OnPORJ14feS1DofEYh1B03mgTxrke5kVx6shPoxpyKE'
    })
    console.log(result)
    return result
  } catch (err) {
    console.log(err)
    return err
  }
}